unit u_FormaPgto;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, upai, FMTBcd, DBClient, Provider, DB, SqlExpr, Grids, DBGrids,
  StdCtrls, Mask, DBCtrls, Menus, dxCore, dxButton, ExtCtrls, JvExMask,
  JvSpin, JvDBSpinEdit;

type
  Tf_FormaPgto = class(TfPai)
    lbl1: TLabel;
    lbl2: TLabel;
    dbedtID_FAMILIA: TDBEdit;
    dbedtDESCRICAO: TDBEdit;
    dbgrd1: TDBGrid;
    pnl1: TPanel;
    lbl3: TLabel;
    lbl4: TLabel;
    s_formapgto: TSQLDataSet;
    p_formapgto: TDataSetProvider;
    ds_formapgto: TClientDataSet;
    s_formapgtoID_FORMAPGTO: TIntegerField;
    s_formapgtoFORMAPGTO: TStringField;
    ds_formapgtoID_FORMAPGTO: TIntegerField;
    ds_formapgtoFORMAPGTO: TStringField;
    lbl5: TLabel;
    dbcbbCONSOLIDA: TDBComboBox;
    lbl6: TLabel;
    JvDBSpinEdit1: TJvDBSpinEdit;
    s_formapgtoCONSOLIDA: TStringField;
    s_formapgtoDIASCONSOLIDA: TIntegerField;
    ds_formapgtoCONSOLIDA: TStringField;
    ds_formapgtoDIASCONSOLIDA: TIntegerField;
    procedure btnGravarClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btnIncluirClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  f_FormaPgto: Tf_FormaPgto;

implementation

uses UDM;

{$R *.dfm}

procedure Tf_FormaPgto.btnGravarClick(Sender: TObject);
begin
  if (ds_formapgto.State = dsInsert) then
  begin
    if dm.c_6_genid.Active then
      dm.c_6_genid.Close;
    dm.c_6_genid.CommandText := 'SELECT CAST(GEN_ID(gen_formapgto, 1) AS INTEGER) AS CODIGO FROM RDB$DATABASE';
    dm.c_6_genid.Open;
    ds_formapgtoID_FORMAPGTO.AsInteger:=dm.c_6_genidCODIGO.AsInteger;
    dm.c_6_genid.Close;
  end;
  inherited;

end;

procedure Tf_FormaPgto.FormShow(Sender: TObject);
begin
//  inherited;
 Incluir := 'S';
 Excluir := 'S';
 Alterar := 'S';
 Cancelar := 'S';
 Procurar := 'S';
 if (not ds_formapgto.Active) then
     ds_formapgto.Open;
end;

procedure Tf_FormaPgto.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
 if (ds_formapgto.Active) then
     ds_formapgto.Close;
end;

procedure Tf_FormaPgto.btnIncluirClick(Sender: TObject);
begin
  inherited;
  ds_formapgtoCONSOLIDA.AsString := 'NAO';
  ds_formapgtoDIASCONSOLIDA.AsInteger := 0;  
end;

end.
